package hacker_rank.feb14;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.PriorityQueue;

public class CuttingBoards {
	private final static long k = 1000000007;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int T = Integer.parseInt(br.readLine());
		for (int t = 0; t < T; t++) {
			String[] line = br.readLine().split(" ");
			int M = Integer.parseInt(line[0]) - 1;
			int N = Integer.parseInt(line[1]) - 1;
			line = br.readLine().split(" ");
			Long[] Y = new Long[M];
			for (int m = 0; m < M; m++) {
				Y[m] = Long.parseLong(line[m]);
			}
			line = br.readLine().split(" ");
			Long[] X = new Long[N];
			for (int n = 0; n < N; n++) {
				X[n] = Long.parseLong(line[n]);
			}
			solve(X, Y);

		}
	}

	private static void solve(Long[] X, Long[] Y) {

		PriorityQueue<Long> xq = new PriorityQueue<Long>(X.length,
				Collections.reverseOrder());
		PriorityQueue<Long> yq = new PriorityQueue<Long>(Y.length,
				Collections.reverseOrder());

		for (Long i : X)
			xq.add(i);

		for (Long i : Y)
			yq.add(i);

		long nx = 1;
		long ny = 1;

		long best = 0;

		while (!xq.isEmpty() || !yq.isEmpty()) {
			if (xq.isEmpty()) {
				best = ((best % k) + (yq.remove() % k) * (nx % k)) % k;
				ny++;
			} else if (yq.isEmpty()) {
				best = ((best % k) + (xq.remove() % k) * (ny % k)) % k;
				nx++;
			} else {
				if (xq.peek() > yq.peek()) {
					best = ((best % k) + ((xq.remove() % k) * (ny % k))) % k;
					nx++;
				} else if (yq.peek() > xq.peek()) {
					best = ((best % k) + (yq.remove() % k) * (nx % k)) % k;
					ny++;
				} else if (nx > ny) {
					best = ((best % k) + (yq.remove() % k) * (nx % k)) % k;
					ny++;
				} else {
					best = ((best % k) + (xq.remove() % k) * (ny % k)) % k;
					nx++;
				}
			}
		}
		System.out.println(best);

	}
}
